<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8" />
	<title>附件管理</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
	<link rel="stylesheet" href="/app/laoha/sdk/sdk.css" />
	<link rel="stylesheet" href="/app/laoha/sdk/helper.css" />
	<link rel="stylesheet" href="/app/laoha/sdk/iconfont.css" />
	<style>
		html,
		body,
		.app-wrapper {
			position: relative;
			width: 100%;
			height: 100%;
			margin: 0;
			padding: 0;
		}

		img {
			max-width: 100%;
		}		
	</style>
</head>

<body>
	<div id="root" class="app-wrapper"></div>
	<script src="/app/laoha/sdk/sdk.js"></script>
	<script type="text/javascript">
		// API相关常量
		const LIST_API = "/app/laoha/admin/attach/list";
		const UPLOAD_IMAGE = "/app/laoha/admin/attach/image";
		const UPLOAD_FILE = "/app/laoha/admin/attach/file";
		const DELETE_API = "delete:/app/laoha/admin/attach/delete";


		(function () {
			let amis = amisRequire('amis/embed');
			// 通过替换下面这个配置来生成不同页面
			let amisJSON = {
				"type": "page",
				"title": "附件管理",
				"data": <?= json_encode($params, JSON_UNESCAPED_UNICODE) ?>,
				"body": [
					{
						"type": "tpl",
						//"tpl": "当前权限${rules|json}"
					},
					{
					"type": "crud",
					"api": LIST_API,
					"defaultParams": {
						"perPage": 10
					},
					"columns": [
						{
							"name": "id",
							"label": "ID",
							"type": "text",
						},
						{
							"name": "url",
							"label": "图片",
							"type": "image",
							"src": "${thumb}",
							"height": "45px",
							"width": "45px",
							"thumbMode": "cover",
							"enlargeAble": true,
						},
						{
							"name": "name",
							"label": "文件名",
							"searchable": true
						},
						{
							"name": "user.nickname",
							"label": "上传"
						},
						{
							"name": "urls_count",
							"label": "引用",
						},
						{
							"name": "url",
							"label": "url复制",
							"type": "button",
							"actionType": "copy",
							"content": "${url}"
						},
						{
							"name": "type",
							"label": "类别",
							"filterable": {
								"options": [
									{ "label": "图片", "value": "image" },
									{ "label": "视频", "value": "video" },
									{ "label": "音频", "value": "audio" },
									{ "label": "文件", "value": "file" }
								]
							}
						},
						{
							"name": "file_size",
							"label": "大小",
							"sortable": true,
						},
						{
							"name": "created_at",
							"label": "创建日期",
							"type": "date",
							"searchable": {
								"type": "input-date-range",
								"name": "created_at",
								"label": "日期",
								"format": "YYYY-MM-DD"
							}
						},
						{
							"type": "operation",
							"label": "操作",
							"width": 50,
							"buttons": [
								//删除
								{
									"type": "button",
									"icon": "fa fa-trash text-danger",
									"tooltip": "删除",
									"actionType": "ajax",
									"confirmText": "${urls_count?'<p class=\"text-danger\">此附件有内容相关联,请慎重</p>您确认要删除?':'您确认要删除?'}",
									"api": DELETE_API + "?id=${id}",
									"visibleOn": "${rules.admin || rules.manage}"
								}
							]
						}
					],

				}
			]};
			let amisScoped = amis.embed('#root', amisJSON, {}, { toastPosition: 'center' });
		})();
	</script>
</body>

</html>